{% if Count > 0 %}
  <div class="page-body">
    <div class="container-xl">
      <div class="row row-cards">
        {% for Media in Medias %}
          <div class="col-12 col-xl-6">
            {% if OperType == 'search' %}
              <a class="card card-link card-link-pop rounded-3"
                 href="javascript:medialist_search('{{ Media.tmdb_id }}', '{{ Media.title }}', '{{ Media.type}}')"
                 style="padding:0 0; overflow:hidden">
            {% else %}
              <div class="card card-link-pop rounded-3" style="padding:0 0; overflow:hidden">
            {% endif %}
            {% if Media.vote_average %}
              <div class="ribbon ribbon-top ribbon-bookmark bg-purple">{{ Media.vote_average }}</div>
            {% endif %}
            <div class="row" style="max-height:240px; overflow:hidden">
              <div class="col-4 col-md-3 col-lg-4 col-xl-3" style="padding:0 0">
                <span class="badge badge-pill {% if Media.type== '电影' %}bg-green{% else %}bg-blue{% endif %}"
                    style="position:absolute;top:10px;left:10px;">{{ Media.type}}</span>
                <img src="{% if Media.poster_path %}{{ Media.poster_path }}{% else %}../static/img/no-image.png{% endif %}"
                    class="w-100 h-100 object-cover">
              </div>
              <div class="col">
                <div class="card-body">
                  <h2>
                    {{ Media.title }} <span class="text-muted">({{ Media.year }})</span>
                  </h2>
                  <div>
                    <span class="badge badge-outline {% if Media.fav == 2 %}text-green{% else %}text-orange{% endif %} mb-1">
                      {% if Media.tmdb_id is string and Media.tmdb_id.startswith('DB') %}
                        {{ Media.tmdb_id[3:] }}{% else %}{{ Media.tmdb_id }}{% endif %}
                    </span>
                  </div>
                  <div class="text-muted mb-3 pb-3">
                    {{ Media.overview|truncate(50, True) }}
                  </div>
                </div>
              </div>
            </div>
            {% if OperType != 'search' %}
              <div class="d-flex">
                <a href="javascript:add_medialist_rss_media('{{ Media.title }}','{{ Media.year }}','{{ Media.type}}','{{ Media.tmdb_id }}')"
                   class="card-btn">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-rss me-2 text-muted"
                       width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <circle cx="5" cy="19" r="1"></circle>
                    <path d="M4 4a16 16 0 0 1 16 16"></path>
                    <path d="M4 11a9 9 0 0 1 9 9"></path>
                  </svg>
                  订阅
                </a>
                <a href="javascript:medialist_search('{{ Media.tmdb_id }}', '{{ Media.title }}', '{{ Media.type}}')"
                   class="card-btn">
                  <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search me-2 text-muted"
                       width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
                       stroke-linecap="round" stroke-linejoin="round">
                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                    <circle cx="10" cy="10" r="7"></circle>
                    <line x1="21" y1="21" x2="15" y2="15"></line>
                  </svg>
                  搜索
                </a>
              </div>
            {% endif %}
            {% if OperType != 'search' %}
              </div>
            {% else %}
              </a>
            {% endif %}
          </div>
        {% endfor %}
      </div>
    </div>
  </div>
{% else %}
  <div class="page-body">
    <div class="container-xl d-flex flex-column justify-content-center">
      <div class="empty">
        <div class="empty-img"><img src="./static/img/posting_photo.svg" height="128" alt="">
        </div>
        <p class="empty-title" id="search_tip_title">未找到数据</p>
        <p class="empty-subtitle text-muted" id="search_tip_text">
          没有找到任何电影、电视剧叫这个名字："{{ SearchWord }}"
        </p>
        {% if OperType == 'search' %}
          <div class="empty-action">
            <a href="javascript:navmenu('search?s={{ SearchWord }}')" class="btn btn-primary">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                   stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
                <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
                <line x1="5" y1="12" x2="19" y2="12"/>
                <line x1="5" y1="12" x2="11" y2="18"/>
                <line x1="5" y1="12" x2="11" y2="6"/>
              </svg>
              返回
            </a>
          </div>
        {% endif %}
      </div>
    </div>
  </div>
{% endif %}
<script type="text/javascript">
  //搜索
  function medialist_search(tmdbid, title, type) {
    const param = {"tmdbid": tmdbid, "search_word": title, "media_type": type};
    show_refresh_process("正在搜索 " + title + " ...");
    ajax_post("search", param, function (ret) {
      hide_refresh_process();
      if (ret.code === 0) {
        navmenu('search?s=' + title)
      } else {
        show_fail_modal(ret.msg);
      }
    });
  }

  //点击订阅按钮
  function add_medialist_rss_media(name, year, type, tmdbid) {
    let doubanid;
    if (type === "电影") {
      type = "MOV";
    } else {
      type = "TV";
    }
    if (tmdbid && tmdbid.startsWith("DB:")) {
      doubanid = tmdbid.replace("DB:", "");
      tmdbid = "";
    } else {
      doubanid = "";
    }
    if (!tmdbid || type === "MOV") {
      add_rss_media(name, year, type, tmdbid, doubanid);
    } else {
      show_wait_process();
      ajax_post("get_tvseason_list", {tmdbid: tmdbid}, function (ret) {
        hide_wait_process();
        if (ret.seasons.length === 1) {
          add_rss_media(name, year, type, tmdbid, doubanid);
        } else if (ret.seasons.length > 1) {
          show_rss_seasons_modal(name, year, type, tmdbid, doubanid, ret.seasons);
        } else {
          show_fail_modal(`${name} 添加RSS订阅失败：未查询到季信息！`);
        }
      });
    }
  }

</script>